<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>编辑商家优惠信息</title>
<link href="${rc.getContextPath()}/resources/css/common.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${rc.getContextPath()}/resources/js/jquery.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/resources/js/common.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/resources/js/jquery.validate.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/resources/js/messages_cn.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/resources/js/input.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/js/ajaxupload.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/js/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript">
var base = '${base!}';
var storeId='${(discount.storeId)!}';
function saveDiscount() {
	var form1 = $("#tableForm");
	form1.submit();
};
function initUploadButton(buttonId){
	var button = $("#"+buttonId);
	var exts = "jpg|png|gif",paths = "|";
	new AjaxUpload(button,
	{   
			action: '${base}/discount/admin/uploadImage.html',   
			name: 'uploadFile',
		onSubmit : function(file, ext)
		{     
       		if ( !RegExp( "\.(?:" + exts + ")$$", "i" ).test(file) ) 
       		{
       			$.dialog.alert("只能上传以下类型：" + exts).zindex();
				return false;
			}          		         
		 	},   
		 	onComplete: function(file, response,statusText)
		 	{   
			var response = jQuery.parseJSON(response);
		 		if(response.status=="error")
			{
		 			$.dialog.alert("上传失败！") ;
			}
			else 
			{
				var res = eval(response);
				if (res.result) {
					$("#discountImg").attr("src","${base}" + response.path);
					$("#discountImg").css("display","block");
					$("#hidImageUrl").val(response.path);
					$("#txtLocalUrl").val(file);
					$.dialog.alert("上传成功！") ;
				} else {
					$.dialog.alert("上传失败，请重试！") ;
				}
			}
		}   
	}); 
};
function myAlert(txt) {
	window.parent.$.dialog({
		lock : true,
		content : txt,
		cancelVal : '确定',
		autoSize : true,
		cancel : function() { //请求成功后处理函数。 
		}
	});
}
$(document).ready(function() {
	var $inputForm = $("#tableForm");
	$inputForm.validate({
		errorClass : "fieldError",
		rules : {
			title : {required:true,maxlength:95},
			description : {maxlength:180}
		}
	});
	initUploadButton('btnUpload');
	var url = "${discount.imgUrl}";
	if (!url) {			
		$("#discountImg").css("display","none");//如果没图片，就不显示图片框
	}
});
function goBackToList() {
	var url = base+"/discount/admin/list.html?storeId="+storeId;
	location.href = url;
};
</script>
</head>

<body>
	<div class="path">
		<b>编辑商家优惠信息</b>
	</div>
	<form action="${base!}/discount/admin/update.html" method="post" id="tableForm" name="tableForm" enctype="multipart/form-data">
		<input type="hidden" name="discountId" value="${discount.discountId!}" />
		<input type="hidden" name="storeId" value="${discount.storeId!}" />
		<table class="input tabContent">
			<tbody>
				<tr>
					<th><span class="requiredField">*</span>标题:</th>
					<td>
						<input type="text" name="title" value="${(discount.title)!}"/>
					</td>
					<th><span class="requiredField">*</span>图片:</th>
					<td>
						<input type="text" id='txtLocalUrl' value='${discount.imgUrl!}' readonly="readonly"/>
						<input type="hidden" name="imgUrl" id="hidImageUrl" value='${discount.imgUrl!}'/>
						<input type="button" id="btnUpload" value="上传"/>
					</td>
				</tr>
				<tr>
					<th>此处显示图片:</th>
					<td colspan="3">
						<img src="${base!}${discount.imgUrl!}" alt="" id="discountImg"  width="200" height="200" />
					</td>
				</tr>				
				<tr>
					<th>优惠信息:</th>
					<td colspan="3">
						<textarea name="description" id="ueditTxt" cols="50" rows="5">${(discount.description)!}</textarea>
					</td>
				</tr>				
			</tbody>
		</table>
		<table class="input">
			<colgroup>
				<col width="15%" />
				<col width="35%" />
				<col width="15%" />
				<col width="35%" />
			</colgroup>
			<tr>
				<td></td>
				<td colspan="3">
					<input type="button" class="button" value="保存" onclick='saveDiscount()'/> 
					<input type="button" class="button" value="返回" onclick="goBackToList()" />
				</td>
			</tr>
		</table>
	</form>
</body>
</html>